package com.dbs.donatebooksystem.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.bind.handler.IgnoreTopLevelConverterNotFoundBindHandler;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
@TableName("books")
public class Book {
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    private Integer userId;
    private String bookname;//书名
    private String conditions;//新旧程度
    private String usages;//使用情况
    private int pageCount;//页数
    private String photoUrl;//书籍照片
    private String traceCode;//书籍追溯码
    private String booksCode;//书籍编号
    private String category;//类别
    private String pubAddress;//发布地址


    //生成十六位追数码方法
    public static String generateRandomSixteenDigits() {
        List<Integer> digits = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            digits.add(i);
        }
        Collections.shuffle(digits);
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < 16; i++) {
            result.append(digits.get(i % 10));
        }
        return result.toString();
    }

    public static String generateRandomBooksCode() {
        Random r = new Random();
/*        List<Integer> digits = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            digits.add(i);
        }
        Collections.shuffle(digits);
        StringBuilder result = new StringBuilder();

        for (int i = 0; i < 6; i++) {
            result.append(digits.get(i % 10));
        }*/
        StringBuilder result = new StringBuilder();

        result.append((char)(r.nextInt(26)+ 65));
        for (int i = 0; i < 4; i++) {
            result.append(r.nextInt(10));
        }

        return result.toString();
    }
}
